#ifndef _AS_25DMAPROAD_H_
#define _AS_25DMAPROAD_H_

#include "cocos2d.h"

class AS25DMapRoadCell
{
public:
	enum AS25MapRoadCellData
	{
		LEFT,
		DOWN,
		RIGHT,
		UP
	};
	AS25DMapRoadCell();
	unsigned int _iTextureAtlasIndex;
	unsigned int _iCellX;
	unsigned int _iCellY;
	unsigned char _vData[4];//left down right up
};

class AS25DMapRoad:public cocos2d::Node, public cocos2d::TextureProtocol
{
public:
	AS25DMapRoad();
	~AS25DMapRoad();
	static AS25DMapRoad* create(cocos2d::Texture2D *tex,unsigned int width,unsigned int height);
	bool init(cocos2d::Texture2D *tex,unsigned int width,unsigned int height);
	virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
	//void onDraw(const kmMat4 &transform, bool transformUpdated);

	virtual cocos2d::Texture2D* getTexture() const override;
    virtual void setTexture(cocos2d::Texture2D *texture) override;
    virtual void setBlendFunc(const cocos2d::BlendFunc &blendFunc) override;
    virtual const cocos2d::BlendFunc& getBlendFunc() const override;
	void onCellChange(unsigned int x,unsigned int y,bool open);
	const AS25DMapRoadCell* getRoadCell(unsigned int x,unsigned int y) const;
	int getCellWidth(){return _iCellW;}
	int getCellHeight(){return _iCellH;}
protected:
	void updateBlendFunc();
	void updateMapAtlas(unsigned int x,unsigned int y,bool open=true);
private:
	int _iWidth;
	int _iHeight;
	int _iCellW;
	int _iCellH;
	int _iCapacity;
	std::map<unsigned int,AS25DMapRoadCell*> _mRoadCells;
	cocos2d::TextureAtlas *_textureAtlas;
    cocos2d::BlendFunc _blendFunc;
    cocos2d::BatchCommand _batchCommand;     // render command
};

#endif